package com.bwie.controller;

import com.bwie.pojo.TbUser;
import com.bwie.service.TbUserService;
import com.bwie.utils.R;
import com.bwie.vo.PageInfoVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author LiuWei Chen
 * @version 1.0
 * @description: TODO
 * @date 2025/4/21 15:55
 */
@RestController
@RequestMapping("/user/index")
public class IndexController {
    @Autowired
    TbUserService userService;
    @PostMapping("/login")
    public R login(@RequestBody TbUser user){
        return userService.login(user);
    }
    @PostMapping("/pageList")
    @ApiOperation("用户列表")
    public R pageList(@RequestBody PageInfoVo pageInfoVo){
        return userService.pageList(pageInfoVo);
    }
    @PostMapping("getUserById/{id}")
    public R getUserById(@PathVariable(name = "id") Integer id){
        TbUser user = userService.getById(id);
        return R.OK(user);
    }
    @ApiOperation("商户注册")
    @PostMapping("/addUser")
    public R addUser(@RequestBody @Validated TbUser user){
        return userService.addUser(user);
    }
    @PostMapping("/checkUser")
    public R checkUser(@RequestBody TbUser user){
        return userService.checkUser(user);
    }

    /**
     * 获取自己信息
     * @return
     */
    @PostMapping("/getMyInfo")
    public R getMyInfo(){
        return userService.getMyInfo();
    }
    /**
     * 商户修改
     */
    @PostMapping("/updateUser")
    public R updateUser(@RequestBody @Validated TbUser user){
        return userService.updateUser(user);
    }
    /**
     * 图片上传
     */
    @PostMapping("/uploadFile")
    public R uploadFile(@RequestPart("file")MultipartFile file){
        return userService.updloadFile(file);
    }
    /**
     * 跟据ID删除
     */
    @PostMapping("/deleteById/{userId}")
    public R deleteById(@PathVariable("userId") Integer userId){
        return userService.deleteByUserId(userId);
    }
}
